Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vite): Support fileReplacements for devServer #13761

Merged
merged 3 commits into from
Dec 13, 2022
Merged

fix(vite): Support fileReplacements for devServer #13761

merged 3 commits into from
Dec 13, 2022

Conversation

nodegin
Copy link
Contributor

@nodegin nodegin commented Dec 12, 2022

Current Behavior

The fileReplacements option does not work with @nrwl/vite:dev-server executor

Existing solution using resolveId only works when building but not local dev

Expected Behavior

When also passing fileReplacements in the "serve" section for the dev server,

It should also do the replacement

Related Issue(s)

Fixes #13758

@vercel
Copy link

vercel bot commented Dec 12, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
nx-dev ⬜️ Ignored (Inspect) Dec 13, 2022 at 9:45AM (UTC)

@mandarini mandarini self-assigned this Dec 12, 2022
@mandarini
Copy link
Member

Hello! Thanks for the PR! Do you want to check your errors and fix them? Then I can approve! Have you tested it, does it work properly in all scenarios?

@mandarini
Copy link
Member

I think format check failed (maybe??). Can you try also nx format?

Copy link
Contributor Author

@nodegin nodegin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mandarini I have amended the fs import

@mandarini
Copy link
Member

@nodegin thanks! Did you also run nx format? Can you force-push again, in any case, because CI is stuck?

@nodegin
Copy link
Contributor Author

nodegin commented Dec 13, 2022

@mandarini Sorry I updated again to format the code.

@mandarini mandarini merged commit b3ff11f into nrwl:master Dec 13, 2022
FrozenPandaz pushed a commit that referenced this pull request Dec 19, 2022
Co-authored-by: ⁢ <john@doe.gov>
(cherry picked from commit b3ff11f)
mandarini added a commit that referenced this pull request Jan 3, 2023
@mandarini
Copy link
Member

@nodegin I reverted your PR because it was causing issues with the source maps. Let me know if you can look into it more, since I guess reverting your PR brings back the devserver issue you had observed.

@KayhanB
Copy link

KayhanB commented Jan 6, 2023

in version 15.4.4 fileReplacements are not working, i downgraded nx to 15.4.2 and now working

@mandarini
Copy link
Member

Are you referring to the build fileReplacements, or the devServer fileReplacements? @KayhanB

@KayhanB
Copy link

KayhanB commented Jan 11, 2023

build is working but devServer is not @mandarini

@mandarini
Copy link
Member

Linking this here

Will take a look at that some time next week.

@mandarini
Copy link
Member

@KayhanB @nodegin I'll see how I can fix this so that both build and dev-server work. However, we do suggest this, using import.meta.env.VITE_*, see these docs

Please let me know if there's a reason why you prefer the fileReplacements solution over this.

@pgsteven
Copy link

@mandarini I think for some case we might want to replace some files (e.g. some code logic to execute?) in different environments instead of just configurations

@mandarini
Copy link
Member

I see. I am working on it!

@mandarini
Copy link
Member

mandarini commented Jan 30, 2023

@nodegin @KayhanB @pgsteven

Hey, people!

So, we decided that this is not in our immediate plans at the moment, after all.

That being said, if any one of you can spend some time putting together a pull request to make this work, I'll be more than happy to test it out, make sure it works, and merge it.

At the same time, if one wants this functionality for Nx, what they can do, is write their own plugin in their workspace, and just add it in the plugins array of their vite.config.js file. I mean, without the plugin needing to be an actual part of Nx. Here's the Plugins API for Vite.

As an alternative, please consider using import.meta.env.VITE_* for variable values, or resolve-alias. I know these do not cover the actual file replacing functionality that you all need for dev server, but they could offer an alternative.

Just as a reminder, fileReplacement does work for the prod builder!

@KayhanB
Copy link

KayhanB commented Feb 2, 2023

hi @mandarini
vite's import.meta.env feature solves my problem perfectly, I didn't know about this feature before you suggested it. I implemented this solution and got a much cleaner result than fileReplacement. for now i don't have a situation where i need to use fileReplacement. If there is, I will inform you.
thank you for attention

@github-actions
Copy link

github-actions bot commented Mar 3, 2023

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Vite] fileReplacements is not working for dev-server
4 participants